<!DOCTYPE html>
<html lang="zh">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>服务器控制</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <!--标准mui.css-->
    <link rel="stylesheet" href="/static/css/mui.min.css">
    <!--App自定义的css-->
    <link rel="stylesheet" type="text/css" href="/static/css/app.css">
</head>
<body>
<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-back mui-pull-left"></a>
    <h1 class="mui-title">运行命令</h1>
</header>
<div class="mui-content">
    <ul class="mui-table-view" id="list">
    </ul>
</div>


</body>
<script src="/static/js/mui.min.js"></script>
<script src="/static/js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" charset="UTF-8">
    //mui初始化
    mui.init({
        swipeBack: true //启用右滑关闭功能
    });

    $(document).ready(function () {
        mui.post('/command/cmdList', function (data) {
                if (data.code === 200) {
                    for (let i = 0; i < data.data.length; i++) {
                        $("#list").append("<li class='mui-table-view-cell' id='" + data.data[i].id + "' onclick='runCmd(" + data.data[i].id + ")' >" + data.data[i].msg + "</li>");
                    }
                } else {
                    mui.toast(data.msg);
                }
            }, 'json'
        );
    })

    function runCmd(id) {
        mui.confirm("确定运行这个指令吗？", "运行", function (e) {
            if (e.index === 1) {
                mui.post('/command/cmd', {
                        id: id
                    }, function (data) {
                        if (data.code === 200) {
                            if (data.data.length < 30) {
                                mui.toast(data.data)
                            } else {
                                alert(data.data)
                            }
                        } else {
                            mui.toast(data.msg);
                        }
                    }, 'json'
                );
            }
        });
    }
</script>

</html>